package com.yunzone.cloud.module.order;


import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yunzone.cloud.common.entity.Result;
import com.yunzone.cloud.module.pay.service.PaymentFeignService;
import com.yunzone.cloud.modules.payment.entity.Payment;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
//@DefaultProperties(defaultFallback = "gloableFallbackMethod")
public class OrderController {
    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping("/success/{id}")
    //@HystrixCommand//加了@DefaultProperties属性注解，并且没有写具体方法名字，就用统一全局的
    public Result<Payment> success(@PathVariable("id") long id){
        return paymentFeignService.paymentSuccess(id);
    }

    @GetMapping("/fail/{id}")
    /*@HystrixCommand(fallbackMethod = "failHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    })*/
    //@HystrixCommand
    public Result<Payment> fail(@PathVariable("id") long id){
        int a=10/0;
        return paymentFeignService.paymentFail(id);
    }

    /*public Result<Payment> failHandler(@PathVariable("id") long id){
        return new Result(555,false,"响应异常，来自80，请稍后再试，"+Thread.currentThread().getName());
    }


    public Result<Payment> gloableFallbackMethod(){
        return new Result(555,false,"响应异常（全局），来自80，请稍后再试，"+Thread.currentThread().getName());
    }*/


}





